I'm using gdb in an attempt to debug my program. gdb has made me aware that line 17 is where the fault occurs. For some reason my input parameters for main become zero.
Breakpoint 2, main (argc=0, argv=0x401c0000) at polygon.c:17
17 fclose(fp);
Consequently Line 18 can't access them. I tried to print the variables, and received the warning "Cannot access memory at address 0x401c0008C" I'm stumped. I have no idea why it's not working. Please help
Code:
# include<stdio.h># define MAXIMUM_SIZE 50
int get_corners(FILE *fp,
double matrix_x[MAXIMUM_SIZE], double
matrix_y[MAXIMUM_SIZE]);
void output_corners(FILE *fp, double array1[], double array2[], int actual_size);
int main( int argc, char *argv[])
{
FILE* fp;
int actual_size;
double matrix_x[MAXIMUM_SIZE], matrix_y[MAXIMUM_SIZE];
fp = fopen(argv[1], "r");
actual_size = get_corners( fp, &matrix_x[MAXIMUM_SIZE], &matrix_y[MAXIMUM_SIZE]);
fclose(fp);
fp = fopen(argv[2], "w");
output_corners( fp, &matrix_x[MAXIMUM_SIZE], &matrix_y[MAXIMUM_SIZE], actual_size);
return(0);
}
int get_corners(FILE *fp,
double matrix_x[MAXIMUM_SIZE], double matrix_y[MAXIMUM_SIZE])
{
double x_cord, y_cord;
int i = 0, input_status, matrix_size;
fscanf(fp, "%lf", &x_cord);
input_status = fscanf(fp, "%lf", &y_cord);
matrix_size = 0;
while (input_status != EOF ) {
printf("%lf\n", x_cord);
matrix_x[i] = x_cord;
matrix_y[i] = y_cord;
i = i + 1;
input_status = fscanf(fp, "%lf", &x_cord);
fscanf(fp, "%lf", &y_cord);
matrix_size += 1;
};
return (matrix_size);
}
void output_corners(FILE *fp, double matrix_x[], double matrix_y[], int actual_size)
{
int i;
for (i = 0 ; i < ( actual_size - 1 ) ;
++i){
fprintf(fp, "%.1lf %.1lf\n", matrix_x[i], matrix_y[i]);
}
printf("%lf", matrix_x[1]);
}